﻿using justice.Models;
using justice.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace justice.Controllers
{
    [Authorize]
    public class ExportController : Controller
    {
        justiceEntities dal = new justiceEntities();
        /// <summary>
        /// 委托书导出列表
        /// </summary>
        /// <param name="pageNum"></param>
        /// <param name="sewhere"></param>
        /// <returns></returns>
        public ActionResult Index(int? pageNum, string sewhere)
        {
            justice_user user = dal.justice_user.ToList().Find(l => l.id == Convert.ToInt32(Session["uid"]));
            string where = "";

            if (user.insurer_id != null)
            {
                var dataa = from sb in dal.Shroff_book
                            join ju in dal.justice_user on sb.enter_user_id equals ju.id
                            join jc in dal.judiciary on ju.unit_id equals jc.id
                            join ir in dal.inserer on sb.insurer equals ir.insurer_id into left
                            from ir in left.DefaultIfEmpty()
                            where sb.insurer == user.insurer_id
                            select new shroffbooklist
                            {
                                shroffbook_id = sb.shroff_id,
                                tablenumber = sb.shroff_number,
                                time = sb.consignation_date,
                                judiciaryName = jc.judiciaryName,
                                insurerName = ir.insurerName
                            };
                Dictionary<List<shroffbooklist>, int[]> _list = Page.Page<shroffbooklist>.Data2(dataa.ToList(), pageNum);
                ViewBag.list = _list.ElementAt(0).Key;
                ViewBag.PageNum = _list.ElementAt(0).Value[0];
                ViewBag.PageSize = _list.ElementAt(0).Value[1];
                ViewBag.PageCount = _list.ElementAt(0).Value[2];
                return View(user);
            }

            if (user.unit_id == null && user.insurer_id == null)
            {
                where = "-";
            }
            else if (user.unit_id != null)
            {
                judiciary jud = dal.judiciary.ToList().Find(l => l.id == user.unit_id);
                where = jud.abbreviation;
            }

            var data = from sb in dal.Shroff_book
                       join ju in dal.justice_user on sb.enter_user_id equals ju.id
                       join jc in dal.judiciary on ju.unit_id equals jc.id
                       join ir in dal.inserer on sb.insurer equals ir.insurer_id into left
                       from ir in left.DefaultIfEmpty()
                       where sb.shroff_number.Contains(@where)
                       select new shroffbooklist
                       {
                           shroffbook_id = sb.shroff_id,
                           tablenumber = sb.shroff_number,
                           time = sb.consignation_date,
                           judiciaryName = jc.judiciaryName,
                           insurerName = ir.insurerName
                       };
            Dictionary<List<shroffbooklist>, int[]> list = Page.Page<shroffbooklist>.Data2(data.ToList(), pageNum);
            ViewBag.list = list.ElementAt(0).Key;
            ViewBag.PageNum = list.ElementAt(0).Value[0];
            ViewBag.PageSize = list.ElementAt(0).Value[1];
            ViewBag.PageCount = list.ElementAt(0).Value[2];
            return View(user);
        }
        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="pageNum"></param>
        /// <param name="sewhere"></param>
        /// <returns></returns>
        public ActionResult Search(int? pageNum, string sewhere)
        {
            justice_user user = dal.justice_user.ToList().Find(l => l.id == Convert.ToInt32(Session["uid"]));
            string where = "";

            if (user.insurer_id != null)//保险公司身份
            {
                var dataa = from sb in dal.Shroff_book
                            join ju in dal.justice_user on sb.enter_user_id equals ju.id
                            join jc in dal.judiciary on ju.unit_id equals jc.id
                            join ir in dal.inserer on sb.insurer equals ir.insurer_id into left
                            from ir in left.DefaultIfEmpty()
                            where sb.insurer == user.insurer_id
                            select new shroffbooklist
                            {
                                shroffbook_id = sb.shroff_id,
                                tablenumber = sb.shroff_number,
                                time = sb.consignation_date,
                                judiciaryName = jc.judiciaryName,
                                insurerName = ir.insurerName
                            };
                if (sewhere != null)
                    dataa = dataa.Where(l => l.tablenumber.Contains(sewhere));
                Dictionary<List<shroffbooklist>, int[]> _list = Page.Page<shroffbooklist>.Data2(dataa.ToList(), pageNum);
                ViewBag.list = _list.ElementAt(0).Key;
                ViewBag.PageNum = _list.ElementAt(0).Value[0];
                ViewBag.PageSize = _list.ElementAt(0).Value[1];
                ViewBag.PageCount = _list.ElementAt(0).Value[2];
                return View(user);
            }

            if (user.unit_id == null && user.insurer_id == null)//超管身份
            {
                where = "-";
            }
            else if (user.unit_id != null)//鉴定机构身份
            {
                judiciary jud = dal.judiciary.ToList().Find(l => l.id == user.unit_id);
                where = jud.abbreviation;
            }

            var data1 = from sb in dal.Shroff_book
                        join ju in dal.justice_user on sb.enter_user_id equals ju.id
                        join jc in dal.judiciary on ju.unit_id equals jc.id
                        join ir in dal.inserer on sb.insurer equals ir.insurer_id into left
                        from ir in left.DefaultIfEmpty()
                        where sb.shroff_number.Contains(@where)
                        select new shroffbooklist
                        {
                            shroffbook_id = sb.shroff_id,
                            tablenumber = sb.shroff_number,
                            time = sb.consignation_date,
                            judiciaryName = jc.judiciaryName,
                            insurerName = ir.insurerName
                        };
            if (sewhere != null)
                data1 = data1.Where(l => l.tablenumber.Contains(sewhere));
            Dictionary<List<shroffbooklist>, int[]> list = Page.Page<shroffbooklist>.Data2(data1.ToList(), pageNum);
            ViewBag.list = list.ElementAt(0).Key;
            ViewBag.PageNum = list.ElementAt(0).Value[0];
            ViewBag.PageSize = list.ElementAt(0).Value[1];
            ViewBag.PageCount = list.ElementAt(0).Value[2];
            ViewBag.search = sewhere;
            return View("shroffbookIndex");
        }
        /// <summary>
        /// 导出鉴定委托书
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FileResult ExportExcel(int id)
        {
            Shroff_book shk = dal.Shroff_book.ToList().Find(l => l.shroff_id == id);
            be_appraiser beap = dal.be_appraiser.ToList().Find(l => l.user_id == shk.main_case);
            nationality nation = dal.nationality.ToList().Find(l => l.id == beap.nationality);
            inserer inser = dal.inserer.ToList().Find(l => l.insurer_id == shk.insurer);
            var sbHtml = new StringBuilder();
            sbHtml.Append("<!DOCTYPE html>");
            sbHtml.Append("<body>");
            sbHtml.AppendFormat("<div style='font-size: 20px;text-align:center;'>{0}</div>", "司法鉴定委托书");
            sbHtml.AppendFormat("<div style='font-size: 20px;'>{0}{1}</div>", "表格编号:",shk.shroff_number);
            sbHtml.Append("<table border='1'width='100%'>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>","委托人");
            sbHtml.AppendFormat("<td>{0}</td>", shk.client);
            sbHtml.AppendFormat("<td>{0}</td>", "联系人");
            sbHtml.AppendFormat("<td>{0}</td>", shk.contact_user);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "联系地址");
            sbHtml.AppendFormat("<td>{0}</td>", shk.contact_readdress);
            sbHtml.AppendFormat("<td>{0}</td>", "联系电话");
            sbHtml.AppendFormat("<td>{0}</td>", shk.contact_phone);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "委托日期");
            sbHtml.AppendFormat("<td>{0}</td>", shk.consignation_date);
            sbHtml.AppendFormat("<td>{0}</td>", "送检人");
            sbHtml.AppendFormat("<td>{0}</td>", shk.submit_check_user);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "与鉴定有关的基本案情");
            sbHtml.AppendFormat("<td colspan='3'>{0}","被鉴定人情况");
            sbHtml.Append("<table border='1' style='width:100%;'>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "姓名");
            sbHtml.AppendFormat("<td>{0}</td>", beap.username);
            sbHtml.AppendFormat("<td>{0}</td>", "性别");
            sbHtml.AppendFormat("<td>{0}</td>", beap.sex);
            sbHtml.AppendFormat("<td>{0}</td>", "族别");
            sbHtml.AppendFormat("<td>{0}</td>", nation.nationalityName);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "出生年月");
            sbHtml.AppendFormat("<td>{0}</td>", beap.date_of_birth);
            sbHtml.AppendFormat("<td>{0}</td>", "文化程度");
            sbHtml.AppendFormat("<td>{0}</td>", beap.culture_degree);
            sbHtml.AppendFormat("<td>{0}</td>", "职业");
            sbHtml.AppendFormat("<td>{0}</td>", beap.profession);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "身份证号");
            sbHtml.AppendFormat("<td colspan='4'>{0}</td>", beap.ID_card);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "现住址");
            sbHtml.AppendFormat("<td colspan='4'>{0}</td>", beap.present_readdress);
            sbHtml.Append("</tr>");
            sbHtml.Append("</table>");
            sbHtml.Append("</td>");
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "委托鉴定事项");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.consignation_transaction);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "是否属于重新鉴定");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.is_re_shroff);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定材料");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.shroff_material);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定用途");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.shroff_purpose);
            sbHtml.Append("</tr>");
            if (shk.insurer != null)
            {
                sbHtml.Append("<tr>");
                sbHtml.AppendFormat("<td>{0}</td>", "涉保理赔保险公司");
                sbHtml.AppendFormat("<td colspan='3'>{0}</td>", inser.insurerName);
                sbHtml.Append("</tr>");
            }
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定时限");
            string[] shrtime = shk.shroff_time_limit.Split('*');
            sbHtml.AppendFormat("<td colspan='3'>1.一般在 {0} 个工作日内；2.遇到特殊情况知会双方延期至 {1} 个工作日。</td>", shrtime[0],shrtime[1]);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td rowspan='2'>{0}</td>", "鉴定费用以及收取方式");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.get_shroff_money_type);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.Append("<td colspan='3'>");
            sbHtml.AppendFormat("<span >{0}</span>", shk.shroff_money);
            sbHtml.AppendFormat("<span>{0}</span>", shk.shroff_money_majuscular);
            sbHtml.Append("</td>");
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定文书发送方式");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.document_methods);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td colspan='4'>{0}", "约定事项");
            sbHtml.AppendFormat("<div>{0}</div>", "1.鉴定机构应当严格遵照有关技术规范保管和使用鉴定材料。鉴定委托人同意或者认可");
            sbHtml.AppendFormat("<div>{0}</div>", "因鉴定需要耗尽鉴定材料；");
            sbHtml.AppendFormat("<div>{0}</div>", "因鉴定需要可能损坏鉴定材料；");
            sbHtml.AppendFormat("<div>{0}</div>", "鉴定完成后无法完整退还鉴定材料；");
            sbHtml.AppendFormat("<div>{0}</div>", "检材留样保存三个月；");
            sbHtml.AppendFormat("<div>2.鉴定时限：从该委托书生效之日起{0}个工作日；</div>",shk.shroff_time);
            sbHtml.AppendFormat("<div>{0}</div>", "注：鉴定过程中补充或重新提取鉴定材料所需的时间，不计入鉴定时限。");
            sbHtml.AppendFormat("<div>{0}</div>", "3.特殊情形鉴定：");
            sbHtml.AppendFormat("<div>{0}</div>", "需要对女性做妇科检查；");
            sbHtml.AppendFormat("<div>{0}</div>", "需要对未成年人的身体检查；");
            sbHtml.AppendFormat("<div>{0}</div>", "需要对被鉴定人进行法医精神病鉴定；");
            sbHtml.AppendFormat("<div>{0}</div>", "需要到现场提取材料；");
            sbHtml.AppendFormat("<div>{0}</div>", "需要进行尸体解剖；");
            sbHtml.AppendFormat("<div>4.委托人要求鉴定人回避，被要求回避的鉴定人签名：{0}；</div>",shk.shroff_user_qian);
            sbHtml.AppendFormat("<div>{0}</div>", "5.鉴定过程中需要变更委托书内容，由双方协商确定。");
            sbHtml.Append("<div>6.其他约定事项。</div>");
            sbHtml.AppendFormat("</td>");
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "其他说明事项");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.other_transaction);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定风险提示");
            sbHtml.Append("<td colspan='3'>");
            sbHtml.Append("<div>1.委托人应向鉴定机构提供真实、完整、充分的鉴定材料，并对其真实性、合法性负责。</div>");
            sbHtml.Append("<div>2.鉴定意见属于专家专业性意见，其是否被 采信取决于办案机关的审查和判断，鉴定人和鉴定机构无权干涉。</div>");
            sbHtml.Append("<div>3.由于鉴定材料和客观条件限制，并非所有的鉴定都能得出明确的鉴定意见。</div>");
            sbHtml.Append("<div>4.鉴定活动遵循依法独立、客观、公正的原则，因此，鉴定意见可能对一方有利，另一方不利。</div>");
            sbHtml.Append("</td>");
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td colspan='2'>委托人(机构)<br />(签名或者盖章)：<br /><br /><br /><div style='text-align:right;margin-right:20px;'>电话撒谎</div></td>", "");
            sbHtml.AppendFormat("<td colspan='2'><div style='float:left;'>接收委托的鉴定机构</div>(签名或者盖章):</td>", "");
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td colspan='4'>{0}</td>", "监督管理管理电话：绵阳市司法局0816-2264821");
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "备注");
            sbHtml.AppendFormat("<td colspan='3'>{0}</td>", shk.remarks);
            sbHtml.Append("</tr>");
            if (shk.insurer != null)
            {
                string[] inform = shk.inform_insurer.Split('*');
                sbHtml.Append("<tr>");
                sbHtml.AppendFormat("<td>{0}</td>", "通知保险公司");
                sbHtml.Append("<td colspan='3'>");
                sbHtml.AppendFormat("<div>时间:</div>", inform[0]);
                sbHtml.AppendFormat("<div>通知人:</div>", inform[1]);
                sbHtml.AppendFormat("<div>联系电话:</div>", inform[2]);
                sbHtml.Append("</td>");
                sbHtml.Append("</tr>");
            }
            sbHtml.Append("</table>");
            sbHtml.Append("</body>");
            //第一种:使用FileContentResult
            byte[] fileContents = Encoding.Default.GetBytes(sbHtml.ToString());
            return File(fileContents, "application/ms-word", string.Format("委托书报表({0}).doc",shk.shroff_number));
        }
        /// <summary>
        /// 导出法医学鉴定意见书
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FileResult ExportExcel2(int id)
        {
            Shroff_book shk = dal.Shroff_book.ToList().Find(l => l.shroff_id == id);
            ForensicOpinion fon = dal.ForensicOpinion.ToList().Find(l=>l.DoctorShroff_id == id);
            be_appraiser beap = dal.be_appraiser.ToList().Find(l=>l.user_id == shk.main_case);
            justice_user user = dal.justice_user.ToList().Find(l=>l.id == shk.enter_user_id);
            judiciary jud = dal.judiciary.ToList().Find(l=>l.id == user.unit_id);
            var sbHtml = new StringBuilder();
            sbHtml.Append("<!DOCTYPE html>");
            sbHtml.Append("<body>");
            sbHtml.AppendFormat("<div style='font-size: 20px;text-align:center;'>{0}</div>", "法医学鉴定意见书");
            sbHtml.AppendFormat("<div style='font-size: 20px;'>{0}{1}</div>", "表格编号:", shk.shroff_number);
            sbHtml.Append("<table border='1'width='100%'>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "委托人");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", shk.client);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "委托事项");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", shk.consignation_transaction);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "送鉴材料");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", shk.shroff_material);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "受理日期");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", shk.consignation_date);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定人");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", shk.shroff_user_qian);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定日期");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", fon.Shroff_data);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定地点");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", jud.readdress);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "被鉴定人");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", beap.username);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "检查摘要");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", fon.Testcase);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "检查过程");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", fon.Inspectionprocess);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "分析说明");
            sbHtml.AppendFormat("<td colspan=3>{0}</td>", fon.Analysishows);
            sbHtml.Append("</tr>");
            sbHtml.Append("<tr>");
            sbHtml.AppendFormat("<td>{0}</td>", "鉴定意见");
            sbHtml.Append("<td colspan=3>");
            sbHtml.AppendFormat("<div>({0})的伤残等级评为: ({1})</ div > ",beap.username,fon.Expertopinion);
            sbHtml.AppendFormat("<div style='margin: 20px 20 % 10px 0; text - align:right; '>鉴定人：{0}</ div > ",fon.Judger);
            sbHtml.Append("</td>");
            sbHtml.Append("</tr>");
            sbHtml.Append("</table>");
            sbHtml.Append("</body>");
            //第一种:使用FileContentResult
            byte[] fileContents = Encoding.Default.GetBytes(sbHtml.ToString());
            return File(fileContents, "application/ms-word", string.Format("法医学鉴定意见书({0}).doc",shk.shroff_number));
        }
		//导出鉴定材料
        public ActionResult ExportMakingsCirculation(int id)
        {
            Shroff_book shroff_book = dal.Shroff_book.ToList().Find(l => l.shroff_id == id);//查委托书
            be_appraiser be_appraiser = dal.be_appraiser.ToList().Find(l => l.user_id == shroff_book.main_case);//根据委托书查被鉴定人
            MakingsCirculation mak = dal.MakingsCirculation.ToList().Find(l => l.ShroffId == id);//查鉴定材料
            ViewBag.TableNumber = shroff_book.shroff_number;
            ViewBag.Client = shroff_book.client;
            ViewBag.be_appraiser_name = be_appraiser.username;
            //鉴定材料
            string[] makingsReceptionPeoples = new string[] { };
            Dictionary<string, string> m = new Dictionary<string, string>();
            if (mak.MakingsReceptionPeoples != null)
            {
                makingsReceptionPeoples = mak.MakingsReceptionPeoples.Split('*'); foreach (var item in makingsReceptionPeoples)
                {
                    if (item != "")
                    {
                        string[] s = item.Split(',');
                        m.Add(s[0], s[1]);
                    }
                }
            }
            List<string> list = new List<string>(m.Keys);

            StringBuilder htmlStr = new StringBuilder();
            htmlStr.Append("<form action='#' method='post'>");
            htmlStr.Append("<div class='page_title'>西科大鉴定材料流转单</div>"); 
            htmlStr.Append("<div class='table_number'>表格编号：" + shroff_book.shroff_number + "</div>"); 
            htmlStr.Append("<table class='makingsCirculation_table' border='1'>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td style=''>委托人</td>");
            htmlStr.Append("<td style=''>" + shroff_book.client + "</td>");
            htmlStr.Append("<td style=''>被鉴定人</td>");
            htmlStr.Append("<td>" + be_appraiser.username + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td><div style='width:23px;margin:auto;margin-top:7 %;'>鉴定材料(包括材料名称和数量)</div></td>");
            htmlStr.Append("<td colspan='3'>" + mak.ShroffMakings + "</td>");
            htmlStr.Append("</tr>");
            if (list != null)
            {
                for (int i = 0; i < list.Count - 1; i++)
                {
                    htmlStr.Append("<tr>");
                    htmlStr.Append("<td>第" + (i + 1) + "鉴定资料收领人</td>");
                    htmlStr.Append("<td>" + list[i] + "</td>");
                    htmlStr.Append("<td>收领日期</td>");
                    htmlStr.Append("<td>" + m[list[i]] + "</td>");
                    htmlStr.Append("</tr>");
                }
            }
            htmlStr.Append("<tr>");
            htmlStr.Append("<td>档案室资料收领人</td>");
            htmlStr.Append("<td>" + list[m.Count - 1] + "</td>");
            htmlStr.Append("<td>归档日期</td>");
            htmlStr.Append("<td>" + m[list[m.Count - 1]] + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td>备注</td>");
            htmlStr.Append("<td colspan='3'>" + mak.Remarks + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("</table>");
            htmlStr.Append("</form>");

            Response.ContentType = "application/force-download";
            Response.AddHeader("content-disposition", "attachment; filename=" + "鉴定材料流转单" + DateTime.Now.ToString("yyyyMMdd") + ".doc");
            Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:word\">");
            Response.Write("<head>");
            Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
            Response.Write("<style type='text/css'>");
            Response.Write("form{ width:1000px; background: white;padding-left: 7 %;padding-right: 7 %;padding-bottom: 2 %;padding-top: 2 %;margin:auto;border:3px solid red;text-align:center;}");
            //Response.Write("table,table tr td{border:1px solid black;}");
            Response.Write(".page_title{width: 100%;height: 55px;color:black;font-size: 25px;line-height: 55px;text-align: center;font-weight: 700;}");
            Response.Write("</style>");
            Response.Write("</head>");
            Response.Write(htmlStr);//这里是前台页面的HTML
            Response.Flush();
            Response.End();
            return View();
        }
        //导出法医临床学检查笔录
        public ActionResult ExportForensicExaminationRecord(int id)
        {
            Shroff_book shroff_book = dal.Shroff_book.ToList().Find(l => l.shroff_id == id);//查委托书
            be_appraiser be_appraiser = dal.be_appraiser.ToList().Find(l => l.user_id == shroff_book.main_case);//根据委托书查被鉴定人
            nationality nation = dal.nationality.ToList().Find(l => l.id == be_appraiser.nationality);//被鉴定人族别
            ForensicExaminationRecord foren = dal.ForensicExaminationRecord.ToList().Find(l => l.TableNumber == id);//根据委托书查 法医临床学检查笔录
            ViewBag.ShroffId = shroff_book.shroff_id;//委托书id
            ViewBag.TableNumber = shroff_book.shroff_number;//委托书编号
            ViewBag.Client = shroff_book.client;//委托人
            ViewBag.be_appraiser = be_appraiser;//被鉴定人
            ViewBag.be_appraiser_nationality = nation.nationalityName;//族别
            ViewBag.Foren = foren;//法医临床学检查笔录信息
                                  //计算被鉴定人年龄
            string idcard = be_appraiser.ID_card.Substring(6, 8);
            string dt = DateTime.Now.ToString("yyyyMMdd");
            string age = ((Convert.ToInt32(dt) - Convert.ToInt32(idcard)).ToString()).Substring(0, 2); ;
            //法医临床学检查笔录信息 使用仪器
            string[] str = new string[] { };
            List<string> useTheInstrument = new List<string>();
            if (foren.UseTheInstrument != null)
            {
                str = foren.UseTheInstrument.Split('*');
                foreach (var item in str)
                {
                    if (item != "")
                        useTheInstrument.Add(item);
                }
            }
            ViewBag.UseTheInstrument = useTheInstrument;

            StringBuilder htmlStr = new StringBuilder();
            htmlStr.Append("<form action='#' method='post'>");
            htmlStr.Append("<div class='page_title'>法医临床学检查笔录</div>");
            htmlStr.Append("<div class='table_number'>表格编号：" + shroff_book.shroff_number + "</div>");
            htmlStr.Append("<table class='makingsCirculation_table' border='1'>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='2'>委托人/委托单位</td>");
            htmlStr.Append("<td colspan='4'>" + shroff_book.client + "</td>");
            htmlStr.Append("<td>检查时间</td>");
            htmlStr.Append("<td colspan='2'>" + foren.Time + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td rowspan='2'>被鉴定者</td>");
            htmlStr.Append("<td>姓名</td>");
            htmlStr.Append("<td>" + be_appraiser.username + "</td>");
            htmlStr.Append("<td>性别</td>");
            htmlStr.Append("<td>" + be_appraiser.sex + "</td>");
            htmlStr.Append("<td>年龄</td>");
            htmlStr.Append("<td>" +  age + "</td>");
            htmlStr.Append("<td>籍贯</td>");
            htmlStr.Append("<td>" + nation.nationalityName + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td>住址</td>");
            htmlStr.Append("<td colspan='3'>" + be_appraiser.present_readdress + "</td>");
            htmlStr.Append("<td>受伤史陈诉人</td>");
            htmlStr.Append("<td>" + foren.InjuryHistoryUser + "</td>");
            htmlStr.Append("<td>可靠程度</td>");
            htmlStr.Append("<td>" + foren.Reliability + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='9'>使用方法：" + foren.MethodOfUse + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='9'>使用仪器：");
            for (int i = 0; i < useTheInstrument.Count; i++)
            {
                if (useTheInstrument[i] == "其他")
                {
                    continue;
                }
                htmlStr.Append("<span>" + useTheInstrument[i] + "</span>");
                htmlStr.Append("<span>&nbsp;</span>");
            }
            htmlStr.Append("</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='9'>检查情况："  + foren.CheckTheSituation + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='9'>既往病、伤史：" + foren.InjuryHistory + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='9'>");
            htmlStr.Append("检查人：" + ViewBag.Foren.CheckUser + "&nbsp;&nbsp;&nbsp;");
            htmlStr.Append("摄影人：" + ViewBag.Foren.Photographer + "&nbsp;&nbsp;&nbsp;");
            htmlStr.Append("被检人或在场人：" + ViewBag.Foren.InspectedOrAttendees);
            htmlStr.Append("</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='9'>");
            htmlStr.Append("<div>要求说明:</div>");
            htmlStr.Append("<div>1、本表应由法医师填写，检查人、摄影人、被检人或在场人均应在表格中签字。</div>");
            htmlStr.Append("<div>2、表中所列各项，应认真填写，同事附照片及单项检查报告单。</div>");
            htmlStr.Append("</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("<tr>");
            htmlStr.Append("<td colspan='9'>备注：" + foren.remarks + "</td>");
            htmlStr.Append("</tr>");
            htmlStr.Append("</table>");
            htmlStr.Append("</form>");

            Response.ContentType = "application/force-download";
            Response.AddHeader("content-disposition", "attachment; filename=" + "法医临床学检查笔录" + DateTime.Now.ToString("yyyyMMdd") + ".doc");
            Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:word\">");
            Response.Write("<head>");
            Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
            Response.Write("<style type='text/css'>");
            Response.Write("form{ width:1000px; background: white;padding-left: 7 %;padding-right: 7 %;padding-bottom: 2 %;padding-top: 2 %;margin:auto;border:3px solid red;text-align:center;}");
            //Response.Write("table,table tr td{border:1px solid black;}");
            Response.Write(".page_title{width: 100%;height: 55px;color:black;font-size: 25px;line-height: 55px;text-align: center;font-weight: 700;}");
            Response.Write("</style>");
            Response.Write("</head>");
            Response.Write(htmlStr);//这里是前台页面的HTML
            Response.Flush();
            Response.End();
            return View();
        }
    }
}